<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>商户主页</title>
    <link rel="stylesheet" href="element-ui/lib/theme-chalk/index.css">
    <script src="js/vue.js"></script>
    <script src="element-ui/lib/index.js"></script>
    <script src="js/axios-0.18.0.js"></script>
</head>
<body>
<div id="app">
    <el-row type="flex" justify="space-between" align="middle">
        <el-col :span="1">
            <el-button plain>
                <a v-if="isLoggedIn">{{ merchant.tradeName }}</a>
                <a v-else @click="goToLogin">登录</a>
            </el-button>
        </el-col>
        <el-col :span="12" style="text-align: right;">
            <el-button
                    v-if="isLoggedIn"
                    type="danger"
                    plain
                    @click="logout"
                    style="margin-left: 10px;">
                退出登录
            </el-button>
        </el-col>
    </el-row>

    <el-tabs type="card" @tab-click="handleClick">
        <el-tab-pane label="店铺信息">
            <el-form label-position="left" label-width="100px" :model="merchant" class="demo-form">
                <el-form-item label="店铺名">
                    <span v-if="!isEditing">{{ merchant.tradeName }}</span>
                    <el-input v-else v-model="editableMerchant.tradeName"></el-input>
                </el-form-item>
                <el-form-item label="地址">
                    <span v-if="!isEditing">{{ merchant.address }}</span>
                    <el-input v-else v-model="editableMerchant.address"></el-input>
                </el-form-item>
                <el-form-item label="联系方式">
                    <span v-if="!isEditing">{{ merchant.contact }}</span>
                    <el-input v-else v-model="editableMerchant.contact"></el-input>
                </el-form-item>
                <el-form-item label="关键词">
                    <span v-if="!isEditing">{{ merchant.keyword }}</span>
                    <el-input v-else v-model="editableMerchant.keyword"></el-input>
                </el-form-item>
                <el-form-item label="营业状态">
                    <span v-if="!isEditing">{{ merchant.businessStatus }}</span>
                    <el-radio-group v-else v-model="editableMerchant.businessStatus">
                        <el-radio label="正常营业">正常营业</el-radio>
                        <el-radio label="暂停营业">暂停营业</el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="申请状态">
                    <span>{{ merchant.applicationStatus }}</span>
                </el-form-item>
                <el-form-item label="注册时间">
                    <span>{{ merchant.date }}</span>
                </el-form-item>
                <el-form-item label="营业额">
                    <span>{{ merchant.turnover }}</span>
                </el-form-item>
                <el-form-item v-if="!isEditing">
                    <el-button type="primary" @click="startEditing">编辑</el-button>
                </el-form-item>
                <el-form-item v-else>
                    <el-button type="success" @click="submitEdit">提交</el-button>
                    <el-button @click="cancelEdit">取消</el-button>
                </el-form-item>
                <el-form-item v-if="merchant.applicationStatus !== '已通过' && merchant.applicationStatus !== '申请中'">
                    <el-button type="primary" @click="submitApplication">提交申请</el-button>
                </el-form-item>
            </el-form>
        </el-tab-pane>

        <el-tab-pane label="房型">
            <el-button type="primary" @click="openAddRoomDialog" style="margin-top: 10px;">添加房型</el-button>
            <el-table :data="rooms" border>
                <el-table-column type="expand">
                    <template slot-scope="props">
                        <el-form label-position="left">
                            <el-form-item label="关键词：">
                                <span>{{ props.row.keyword }}</span>
                            </el-form-item>
                            <el-form-item label="床型：">
                                <span>{{ props.row.bedType }}</span>
                            </el-form-item>
                            <el-form-item label="设施：">
                                <span>{{ props.row.facility }}</span>
                            </el-form-item>
                            <el-form-item label="面积：">
                                <span>{{ props.row.area }}</span>
                            </el-form-item>
                            <el-form-item label="人数：">
                                <span>{{ props.row.capacity }}</span>
                            </el-form-item>
                            <el-form-item label="价格：">
                                <span>{{ props.row.price }}</span>
                            </el-form-item>
                            <el-form-item label="剩余数量：">
                                <span>{{ props.row.surplus }}</span>
                            </el-form-item>
                            <el-form-item label="销量：">
                                <span>{{ props.row.salesVolume }}</span>
                            </el-form-item>
                        </el-form>
                    </template>
                </el-table-column>
                <el-table-column prop="keyword" label="关键词" sortable></el-table-column>
                <el-table-column prop="salesVolume" label="销量" sortable></el-table-column>
                <el-table-column prop="price" label="价格" sortable></el-table-column>
                <el-table-column prop="surplus" label="剩余数量" sortable></el-table-column>
                <el-table-column label="操作">
                    <template slot-scope="scope">
                        <el-button size="mini" type="primary" @click="openRoomNumberDialog(scope.row)">房间号
                        </el-button>
                        <el-button size="mini" type="success" @click="openRoomDetailsDialog(scope.row)">修改房型
                        </el-button>
                        <el-button size="mini" type="danger" @click="deleteRoom(scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </el-tab-pane>

        <el-tab-pane label="订单">
            <el-table :data="orders" border>
                <el-table-column prop="clientName" label="客户" sortable></el-table-column>
                <el-table-column prop="roomName" label="房型名" sortable></el-table-column>
                <el-table-column prop="roomNumber" label="房间号" sortable></el-table-column>
                <el-table-column prop="amount" label="订单金额" sortable></el-table-column>
                <el-table-column prop="date" label="订单时间" width="200" sortable></el-table-column>
                <el-table-column prop="tradeStatus" label="交易状态" sortable></el-table-column>
                <el-table-column prop="checkStatus" label="入住状态" sortable></el-table-column>
                <el-table-column label="操作" width="200">
                    <template slot-scope="scope">
                        <el-button size="mini"
                                   v-if="scope.row.tradeStatus === '已支付' && scope.row.checkStatus === '未入住'"
                                   @click="checkIn(scope.row)">
                            已入住
                        </el-button>
                        <el-button size="mini" type="primary"
                                   v-if="scope.row.tradeStatus === '已支付' && scope.row.checkStatus === '正常入住'"
                                   @click="checkOut(scope.row)">
                            退房
                        </el-button>
                        <el-button size="mini" type="danger" @click="addBlacklist(scope.row)">拉黑</el-button>
                        <el-button size="mini" type="danger"
                                   v-if="scope.row.tradeStatus === '退款中'"
                                   @click="refund(scope.row)">
                            退款
                        </el-button>
                        <el-button size="mini" type="danger"
                                   v-if="scope.row.tradeStatus === '退款中'"
                                   @click="refuseRefund(scope.row)">
                            拒绝退款
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
        </el-tab-pane>

        <el-tab-pane label="黑名单">
            <h3 style="text-align: center;">黑名单</h3>
            <el-button type="primary" @click="toggleManagement">管理</el-button>
            <el-table :data="blacklist" style="margin-top: 20px;" border v-if="!isManaging">
                <el-table-column type="index" label="序号" width="50"></el-table-column>
                <el-table-column prop="nickname" label="客户昵称"></el-table-column>
            </el-table>
            <div v-if="isManaging">
                <el-table ref="blacklistTable" :data="blacklist" style="margin-top: 20px;" border>
                    <el-table-column type="selection" width="55"></el-table-column>
                    <el-table-column type="index" label="序号"></el-table-column>
                    <el-table-column prop="nickname" label="客户昵称"></el-table-column>
                </el-table>
                <el-button type="danger" @click="deleteBlacklist">删除黑名单</el-button>
                <el-button @click="toggleManagement">取消</el-button>
            </div>
        </el-tab-pane>
    </el-tabs>

    <el-dialog title="修改房型" :visible.sync="roomDialogVisible" width="30%">
        <el-form label-position="left" label-width="100px" :model="editableRoom">
            <el-form-item label="关键词">
                <el-input v-model="editableRoom.keyword"></el-input>
            </el-form-item>
            <el-form-item label="床型">
                <el-input v-model="editableRoom.bedType"></el-input>
            </el-form-item>
            <el-form-item label="设施">
                <el-input v-model="editableRoom.facility"></el-input>
            </el-form-item>
            <el-form-item label="面积">
                <el-input v-model="editableRoom.area"></el-input>
            </el-form-item>
            <el-form-item label="人数">
                <el-input-number v-model="editableRoom.capacity" :min="0"></el-input-number>
            </el-form-item>
            <el-form-item label="价格">
                <el-input-number v-model="editableRoom.price" :precision="2" :step="1" :min="0"></el-input-number>
            </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
        <el-button @click="cancelRoomEdit">取消</el-button>
        <el-button type="primary" @click="submitRoomEdit">提交</el-button>
    </span>
    </el-dialog>

    <el-dialog title="添加房型" :visible.sync="addRoomDialogVisible" width="30%">
        <el-form label-position="left" label-width="100px" :model="newRoom">
            <el-form-item label="关键词">
                <el-input v-model="newRoom.keyword"></el-input>
            </el-form-item>
            <el-form-item label="床型">
                <el-input v-model="newRoom.bedType"></el-input>
            </el-form-item>
            <el-form-item label="设施">
                <el-input v-model="newRoom.facility"></el-input>
            </el-form-item>
            <el-form-item label="面积">
                <el-input v-model="newRoom.area"></el-input>
            </el-form-item>
            <el-form-item label="人数">
                <el-input-number v-model="newRoom.capacity" :min="0"></el-input-number>
            </el-form-item>
            <el-form-item label="价格">
                <el-input-number v-model="newRoom.price" :precision="2" :step="1" :min="0"></el-input-number>
            </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
            <el-button @click="cancelAddRoom">取消</el-button>
            <el-button type="primary" @click="submitAddRoom">提交</el-button>
        </span>
    </el-dialog>

    <el-dialog title="房间号管理" :visible.sync="roomNumberDialogVisible" width="50%">
        <el-button type="primary" @click="openAddRoomNumberDialog" style="margin-bottom: 10px;">添加房间号</el-button>
        <el-table :data="roomNumbers" border v-if="roomNumbers.length > 0">
            <el-table-column prop="roomNumber" label="房间号"></el-table-column>
            <el-table-column prop="status" label="状态"></el-table-column>
            <el-table-column label="操作">
                <template slot-scope="scope">
                    <el-button size="mini" @click="toggleRoomStatus(scope.row)">切换状态</el-button>
                    <el-button size="mini" type="danger" @click="deleteRoomNumber(scope.row)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
        <div v-else style="text-align: center; margin-top: 20px;">暂无房间号</div>
    </el-dialog>

</div>

<script>
    new Vue({
        el: '#app',
        data() {
            return {
                isLoggedIn: false, // 登录状态
                isEditing: false,
                user: {
                    id: '',
                    phoneNum: '',
                    password: '',
                    userType: ''
                },
                merchant: {
                    id: '',
                    userId: '',
                    tradeName: '',
                    address: '',
                    contact: '',
                    keyword: '',
                    businessStatus: '',
                    applicationStatus: '',
                    date: '',
                    turnover: '',
                    totalSales: ''
                },
                rooms: [],
                editableMerchant: {},
                dialogVisible: false,
                roomDialogVisible: false,
                selectedRoom: null,
                editableRoom: {},
                addRoomDialogVisible: false, // 控制添加房型对话框的显示状态
                newRoom: { // 新房型的数据模型
                    keyword: '',
                    bedType: '',
                    facility: '',
                    area: '',
                    capacity: 0,
                    price: 0,
                    surplus: 0,
                },
                orders: [], // 订单数据
                blacklist: [], // 黑名单数据
                isManaging: false, // 是否处于管理模式
                roomNumberDialogVisible: false,
                roomNumbers: [], // 房间号数据
                selectedRoomNumber: null
            };
        },
        async mounted() {
            await this.checkLoginStatus();
        },
        methods: {
            // 检查登录状态
            checkLoginStatus() {
                const _this = this;
                axios.get('http://localhost:8080/ProjectRound1_war/user/checkLogin').then(response => {
                    if (response.data.code === 200 && response.data.data.user.userType === "merchant") {
                        _this.isLoggedIn = true;
                        _this.user = response.data.data.user;
                        _this.merchant = response.data.data.additionalInfo;
                        _this.editableMerchant = {...response.data.data.additionalInfo};
                        _this.fetchRoomDetails(_this.merchant);
                    } else {
                        _this.isLoggedIn = false;
                    }
                });
            },
            logout() {
                if (!this.isLoggedIn) {
                    window.location.href = 'login.html';
                }
                if (!confirm('确定要退出登录吗？')) {
                    return;
                }
                const _this = this;
                axios.post('http://localhost:8080/ProjectRound1_war/user/logout')
                    .then(() => {
                        _this.isLoggedIn = false;
                        _this.user = {};
                        _this.client = {};
                        alert('退出登录成功');
                        window.location.reload();
                    });
            },
            fetchRoomDetails(merchant) {
                const merchantId = merchant.id;
                const _this = this;
                return axios.post('http://localhost:8080/ProjectRound1_war/merchant/queryRoom', merchantId)
                    .then(response => {
                        if (response.data.code === 200) {
                            _this.rooms = response.data.data;
                        } else {
                            console.error('获取房间信息失败:', response.data.msg);
                        }
                    }).catch(error => {
                        console.error(error);
                    });
            },

            // 跳转到登录页面
            goToLogin() {
                window.location.href = 'login.html';
            },

            // 处理标签页切换
            handleClick(tab) {
                if (tab.label === "黑名单") {
                    this.fetchBlacklist();
                }
                if (tab.label === "订单") {
                    this.fetchOrders();
                }
            },

            startEditing() {
                if (!this.isLoggedIn) {
                    window.location.href = 'login.html';
                    return;
                }
                this.isEditing = true;
            },

            submitEdit() {
                const _this = this;
                axios.post('http://localhost:8080/ProjectRound1_war/merchant/update', {
                    id: _this.merchant.id,
                    userId: _this.user.id,
                    tradeName: _this.editableMerchant.tradeName,
                    address: _this.editableMerchant.address,
                    contact: _this.editableMerchant.contact,
                    keyword: _this.editableMerchant.keyword,
                    businessStatus: _this.editableMerchant.businessStatus,
                }).then(response => {
                    if (response.data.code === 200) {
                        _this.merchant = {..._this.editableMerchant};
                        _this.isEditing = false;
                        _this.$message.success('修改成功');
                    } else {
                        _this.$message.error(response.data.msg);
                    }
                }).catch(error => {
                    console.error(error);
                    _this.$message.error('请求失败');
                });
            },

            cancelEdit() {
                this.editableMerchant = {...this.merchant};
                this.isEditing = false;
            },

            openRoomDetailsDialog(row) {
                this.selectedRoom = row;
                this.editableRoom = {...row};
                this.roomDialogVisible = true;
            },
            cancelRoomEdit() {
                this.roomDialogVisible = false;
                this.editableRoom = {};
            },
            submitRoomEdit() {
                const _this = this;
                axios.post('http://localhost:8080/ProjectRound1_war/merchant/updateRoom', {
                    id: _this.editableRoom.id,
                    keyword: _this.editableRoom.keyword,
                    bedType: _this.editableRoom.bedType,
                    facility: _this.editableRoom.facility,
                    area: _this.editableRoom.area,
                    capacity: _this.editableRoom.capacity,
                    price: _this.editableRoom.price,
                }).then(response => {
                    if (response.data.code === 200) {
                        const index = _this.rooms.findIndex(room => room.id === _this.editableRoom.id);
                        if (index !== -1) {
                            _this.$set(_this.rooms, index, {..._this.editableRoom});
                        }
                        _this.roomDialogVisible = false;
                        _this.$message.success('更改成功！');
                    } else {
                        _this.$message.error(response.data.msg);
                        console.error('更新房型信息失败:', response.data.msg);
                    }
                }).catch(error => {
                    console.error(error);
                    _this.$message.error('请求失败');
                });
            },
            deleteRoom(room) {
                if (!confirm('确定删除该房型吗？')) {
                    return;
                }
                const _this = this;
                axios.post('http://localhost:8080/ProjectRound1_war/merchant/deleteRoom', room.id)
                    .then(response => {
                        if (response.data.code === 200) {
                            const index = _this.rooms.findIndex(r => r.id === room.id);
                            if (index !== -1) {
                                _this.rooms.splice(index, 1);
                            }
                            _this.$message.success('房型删除成功');
                        } else {
                            _this.$message.error(response.data.msg);
                        }
                    }).catch(error => {
                    console.error(error);
                    _this.$message.error('请求失败');
                });
            },
            // 打开添加房型对话框
            openAddRoomDialog() {
                this.addRoomDialogVisible = true;
            },
            // 取消添加房型
            cancelAddRoom() {
                this.addRoomDialogVisible = false;
                this.newRoom = {
                    keyword: '',
                    bedType: '',
                    facility: '',
                    area: '',
                    capacity: 0,
                    price: 0,
                    surplus: 0,
                };
            },
            // 提交添加房型
            submitAddRoom() {
                const _this = this;
                axios.post('http://localhost:8080/ProjectRound1_war/merchant/addRoom', {
                    merchantId: _this.merchant.id,
                    room: this.newRoom,
                })
                    .then(response => {
                        if (response.data.code === 200) {
                            _this.fetchRoomDetails(_this.merchant);
                            _this.$message.success('房型添加成功');
                            _this.cancelAddRoom(); // 清空表单并关闭对话框
                        } else {
                            _this.$message.error(response.data.msg);
                        }
                    }).catch(error => {
                    console.error(error);
                    _this.$message.error('请求失败');
                });
            },
            // 获取订单数据
            fetchOrders() {
                const _this = this;
                axios.post('http://localhost:8080/ProjectRound1_war/merchant/getOrders', _this.user)
                    .then(response => {
                        if (response.data.code === 200) {
                            _this.orders = response.data.data;
                        } else {
                            _this.$message.error('获取订单数据失败');
                        }
                    }).catch(error => {
                    console.error(error);
                    _this.$message.error('获取订单数据失败');
                });
            },
            // 拉黑租户
            addBlacklist(order) {
                const _this = this;
                axios.post('http://localhost:8080/ProjectRound1_war/merchant/addBlacklist', {
                    clientId: order.clientId,
                    merchantId: _this.merchant.id,
                })
                    .then(response => {
                        if (response.data.code === 200) {
                            _this.$message.success('拉黑成功！');
                        } else {
                            _this.$message.error(response.data.msg);
                        }
                    }).catch(error => {
                    console.error(error);
                    _this.$message.error('请求失败');
                });
            },
            // 获取黑名单数据
            fetchBlacklist() {
                if (!this.isLoggedIn) {
                    window.location.href = 'login.html';
                    return;
                }
                const _this = this;
                axios.post('http://localhost:8080/ProjectRound1_war/merchant/getBlacklist', _this.merchant.id)
                    .then(response => {
                        if (response.data.code === 200) {
                            _this.blacklist = response.data.data;
                        } else {
                            console.error(response.data.msg);
                        }
                    }).catch(error => {
                    console.error(error);
                    _this.$message.error('请求失败');
                });
            },
            // 切换管理模式
            toggleManagement() {
                this.isManaging = !this.isManaging;
            },
            // 删除黑名单
            deleteBlacklist() {
                const _this = this;
                const selectedRows = this.$refs.blacklistTable.selection;
                if (selectedRows.length === 0) {
                    _this.$message.warning('请选择要删除的黑名单');
                    return;
                }
                const clientIds = selectedRows.map(row => row.id);
                axios.post('http://localhost:8080/ProjectRound1_war/merchant/cancelBlack', {
                    merchantId: _this.merchant.id,
                    clientIds: clientIds,
                })
                    .then(response => {
                        if (response.data.code === 200) {
                            _this.$message.success('删除黑名单成功');
                            _this.fetchBlacklist();
                            _this.isManaging = false;
                        } else {
                            _this.$message.error('删除黑名单失败');
                        }
                    })
                    .catch(error => {
                        console.error(error);
                        _this.$message.error('请求失败');
                    });
            },

            submitApplication() {
                if (!this.isLoggedIn) {
                    window.location.href = 'login.html';
                    return;
                }
                const _this = this;
                axios.post('http://localhost:8080/ProjectRound1_war/merchant/submitApplication', _this.merchant.id)
                    .then(response => {
                        if (response.data.code === 200) {
                            _this.$message.success('申请提交成功');
                            _this.merchant.applicationStatus = '申请中';
                        } else {
                            _this.$message.error('申请提交失败');
                        }
                    }).catch(error => {
                    console.error(error);
                    _this.$message.error('请求失败');
                });
            },
            refund(order) {
                if (!confirm(`确定要给客户${order.clientName}退款吗？`)) return
                const _this = this
                axios.post('http://localhost:8080/ProjectRound1_war/merchant/refund', order.id)
                    .then(response => {
                        if (response.data.code === 200) {
                            _this.$message.success('退款成功')
                            _this.fetchOrders(_this.merchant)
                        } else if (response.data.code === 30005) {
                            _this.$message.error('营业额不足以退款')
                        } else if (response.data.code === 40005) {
                            _this.$message.error('该订单无需退款')
                        } else {
                            _this.$message.error('退款失败，请稍后重试')
                            console.error('退款请求失败:', response.data.msg)
                        }
                    })
                    .catch(error => {
                        console.error('退款请求失败:', error)
                        _this.$message.error('退款请求失败')
                    })
            },
            // 打开房间号对话框
            openRoomNumberDialog(row) {
                this.selectedRoom = row;
                this.fetchRoomNumbers(row.id);
                this.roomNumberDialogVisible = true;
            },
            // 获取房间号数据
            fetchRoomNumbers(roomId) {
                const _this = this;
                axios.post('http://localhost:8080/ProjectRound1_war/merchant/getRoomNumbers', roomId)
                    .then(response => {
                        if (response.data.code === 200) {
                            _this.roomNumbers = response.data.data;
                        } else {
                            _this.$message.error(response.data.msg);
                        }
                    }).catch(error => {
                    console.error(error);
                    _this.$message.error('获取房间号数据失败');
                });
            },
            // 切换房间号状态
            toggleRoomStatus(roomNumber) {
                const _this = this;
                axios.post('http://localhost:8080/ProjectRound1_war/merchant/toggleRoomStatus', roomNumber.id)
                    .then(response => {
                        if (response.data.code === 200) {
                            _this.$message.success('切换成功');
                            _this.fetchRoomNumbers(_this.selectedRoom.id);
                            _this.fetchRoomDetails(_this.merchant);
                        } else if (response.data.code === 40001) {
                            _this.$message.error('切换失败，存在未完成订单');
                        } else {
                            _this.$message.error('切换失败，请稍后重试');
                        }
                    }).catch(error => {
                    console.error(error);
                    _this.$message.error('请求失败');
                });
            },
            // 删除房间号
            deleteRoomNumber(roomNumber) {
                if (!confirm('确定删除该房间号吗？')) return;
                const _this = this;
                axios.post('http://localhost:8080/ProjectRound1_war/merchant/deleteRoomNumber', roomNumber.id)
                    .then(response => {
                        if (response.data.code === 200) {
                            _this.$message.success('删除成功');
                            _this.fetchRoomNumbers(_this.selectedRoom.id);
                            _this.fetchRoomDetails(_this.merchant);
                        } else if (response.data.code === 40001) {
                            _this.$message.error('删除失败，存在未完成订单');
                        } else {
                            _this.$message.error('删除失败，请稍后重试');
                        }
                    }).catch(error => {
                    console.error(error);
                    _this.$message.error('请求失败');
                });
            },
            // 打开添加房间号对话框
            openAddRoomNumberDialog() {
                this.$prompt('请输入房间号', '房间号', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    inputPattern: /\S+/,
                    inputErrorMessage: '房间号不能为空'
                }).then(({value}) => {
                    const _this = this;
                    axios.post('http://localhost:8080/ProjectRound1_war/merchant/addRoomNumber', {
                        roomId: _this.selectedRoom.id,
                        roomNumber: value
                    }).then(response => {
                        if (response.data.code === 200) {
                            _this.$message.success('房间号添加成功');
                            _this.fetchRoomNumbers(_this.selectedRoom.id);
                            _this.fetchRoomDetails(_this.merchant);
                        } else {
                            _this.$message.error('房间号添加失败');
                        }
                    }).catch(error => {
                        console.error(error);
                        _this.$message.error('请求失败');
                    });
                });
            },

            // 退房方法
            checkOut(order) {
                if (!confirm('确定客户已退房吗？')) return
                const _this = this
                axios.post('http://localhost:8080/ProjectRound1_war/merchant/checkOut', order.id)
                    .then(response => {
                        if (response.data.code === 200) {
                            _this.$message.success('退房成功')
                            _this.fetchOrders(_this.merchant)
                        } else if (response.data.code === 40006) {
                            _this.$message.error('该订单未满足退房条件')
                        } else {
                            _this.$message.error('退房失败，请稍后重试')
                            console.error('退房请求失败:', response.data.msg)
                        }
                    })
                    .catch(error => {
                        console.error(error);
                        _this.$message.error('请求失败');
                    })
            },

            checkIn(order) {
                if (!confirm('确定客户已入住吗？')) return
                const _this = this
                axios.post('http://localhost:8080/ProjectRound1_war/merchant/checkIn', order.id)
                    .then(response => {
                        if (response.data.code === 200) {
                            _this.$message.success('设置为入住成功')
                            _this.fetchOrders(_this.merchant)
                        } else if (response.data.code === 40002) {
                            _this.$message.error('该订单未满足入住条件')
                        } else {
                            _this.$message.error('入住失败，请稍后重试')
                            console.error('入住请求失败:', response.data.msg)
                        }
                    })
                    .catch(error => {
                        console.error(error);
                        _this.$message.error('请求失败');
                    })
            },

            refuseRefund(order) {
                if (!confirm('确定拒绝退款吗？')) return
                const _this = this
                axios.post('http://localhost:8080/ProjectRound1_war/merchant/refuseRefund', order.id)
                    .then(response => {
                        if (response.data.code === 200) {
                            _this.$message.success('拒绝退款成功')
                            _this.fetchOrders(_this.merchant)
                        } else {
                            _this.$message.error('拒绝退款失败，请稍后重试')
                        }
                    })
                    .catch(error => {
                        console.error(error);
                        _this.$message.error('请求失败');
                    })
            }
        }
    });
</script>
</body>
</html>